

function CreateClone($object) 
{
	if(!$object||"object"!== typeof $object) 
	{
		return $object;
	}
	
	var _clone = "function" === typeof $object.pop ? [] : {};
	
	var _property, _value;
	
	for(_property in $object) 
	{
		if($object.hasOwnProperty(_property)) 
		{
			_value = $object[_property];
			if(_value && "object"===typeof _value) 
			{
				_clone[_property] = CreateClone(_value);
			}
			else 
			{
				_clone[_property] = _value;
			}
		}
	}
	return _clone;
}



/********************************************************************************/
/* Copy all properties from a source object to a target object			*/


function CopyProperties($target, $src)
{
	var _msg = "Errors:\n\n";
	for(var _prop in $src)
	{
		try{ 
			$target[_prop] = $src[_prop];
		}catch(e){
			_msg += "Copying property...\n";
			_msg += "PropertyName = "+_prop+"\n";
			_msg += "PropertyValue = "+ $src[_prop]+"\n";
			_msg += "JS ErrMsg = "+ e.description+"\n\n";
		}
	}
	if(_msg!="Errors:\n\n") alert(_msg)
}





 
// Add to EXT
function CopyUndeclaredProperties($to, $from)
{
	for(var i in $from)
	{
		if($to[i]==undefined)
		{
			$to[i] = $from[i];
		}
	}
	return $to;
}



function PopupCode($string)
{
	var _win = window.open("about:blank","_win","");
	_win.document.write("<textarea id='textarea' wrap=off  style='width:100%;height:100%;'></textarea>")
	_win.document.getElementById("textarea").value = $string;
	return _win.document.getElementById("textarea");
}


function loadFormByUrl($owner,$loadUrl,$params){
	
	$owner.load({
		url     : $loadUrl,
		waitMsg : 'Loading...',
		params  : $params,
		failure     : function(form,action) {
			if(action.result.msg == '' || action.result.msg == undefined){
				action.result.msg = '失败';
			}
			Ext.Msg.alert("提示",action.result.msg);
		}
	})
	
}


/**
 * 文章管理  修改页面 删除附件
 * @param {} obj
 * @param {} url
 */
function delFile(obj,url) {
    Ext.Ajax.request({
		   url    : url,
		   method : "POST",
		   success: function(response) {
			   //检查session是否过期
			   checkTimeOut(response);
			   var responseObj = Ext.util.JSON.decode(response.responseText);
			   if(responseObj.success) {
			   		Ext.getCmp(obj.id).setValue("");
			   } else {
			   		alertFailure(responseObj);
			   }
		   }, failure: function(response) {
				Ext.Msg.alert('提示','服务器异常！');
		   }
   });	
}
/**
 * 文章管理  修改页面 删除附件
 * @param {} param1
 * @param {} param2
 * @param {} param3
 */
function deleteFile(param1,param2,param3){
	Ext.Msg.show({
		title : '提示',
		msg : '你确认要删除吗?',
		buttons : {yes:'是',no:'否'},
		fn : function(btn, text){  
	        if (btn == 'yes'){  
				Ext.getCmp(param1).setValue('');
				Ext.getCmp(param2).setValue('');
				Ext.getCmp(param3).setValue(true);
	         } else{
	         	return;
	         }
		}
	})
}

/**
 * 文章管理  修改页面 下载附件
 * @param {} obj
 * @param {} url
 */
function exportFile(url) {
	document.getElementById("downloadFrame").src = url;
}

/**
 *  修改密码
 */
function changePwd() {
	new VAS.UserPasswordEditWindow({
		title   : '密码修改',
		width   :  450
	}).show(); 
}
/**
 *  修改密码
 */
function logOut() {
	Ext.Msg.show({
		title : '提示',
		msg : '确定要退出吗?',
		buttons : {yes:'是',no:'否'},
		fn : function(btn, text){  
		        if (btn == 'yes'){  
		          	var redirect = 'Logout.action';  
		          	window.location = redirect;  
		         } 
			}
	})
}

function homePage() {
	destroyAllOfNewWinArray();
	if(findExistedWin('shortCut')==false){
		var win = new VAS.MainWindow({
			id : 'shortCut'
			,width   :  '100%'
			,height  : 	'100%'
			,y       : 2
			,x       : 2
		}); 
		var portal = Ext.getCmp("std-panel");
		portal.addWindow(win);
	}
}	

function ObjecttoUrl(object){
    for(var prop in object){
		var param="";
		param=prop.replace(/(^\s+)|(\s+$)/g,"")+"="+object[prop].replace(/(^\s+)|(\s+$)/g,"");	
		params=(params=="")?params+param:params+"&"+param;
	}
}


function clone(o) {
 return eval(uneval(o));
}

/**      
* 对Date的扩展，将 Date 转化为指定格式的String      
* 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符      
* 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)      
* eg:      
* (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423      
* (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04      
* (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04      
* (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04      
* (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18      
*/        
Date.prototype.pattern=function(fmt) {         
    var o = {         
    "M+" : this.getMonth()+1, //月份         
    "d+" : this.getDate(), //日         
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时         
    "H+" : this.getHours(), //小时         
    "m+" : this.getMinutes(), //分         
    "s+" : this.getSeconds(), //秒         
    "q+" : Math.floor((this.getMonth()+3)/3), //季度         
    "S" : this.getMilliseconds() //毫秒         
    };         
    var week = {         
    "0" : "\u65e5",         
    "1" : "\u4e00",         
    "2" : "\u4e8c",         
    "3" : "\u4e09",         
    "4" : "\u56db",         
    "5" : "\u4e94",         
    "6" : "\u516d"        
    };         
    if(/(y+)/.test(fmt)){         
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));         
    }         
    if(/(E+)/.test(fmt)){         
        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);         
    }         
    for(var k in o){         
        if(new RegExp("("+ k +")").test(fmt)){         
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));         
        }         
    }         
    return fmt;         
}


Date.prototype.format = function(mask) {     
    var d = this;     
    var zeroize = function (value, length) {     
        if (!length) length = 2;     
        value = String(value);     
        for (var i = 0, zeros = ''; i < (length - value.length); i++) {     
            zeros += '0';     
        }     
        return zeros + value;     
    };       
    
    return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function($0) {     
        switch($0) {     
            case 'd':   return d.getDate();     
            case 'dd':  return zeroize(d.getDate());     
            case 'ddd': return ['Sun','Mon','Tue','Wed','Thr','Fri','Sat'][d.getDay()];     
            case 'dddd':    return ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][d.getDay()];     
            case 'M':   return d.getMonth() + 1;     
            case 'MM':  return zeroize(d.getMonth() + 1);     
            case 'MMM': return ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][d.getMonth()];     
            case 'MMMM':    return ['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];     
            case 'yy':  return String(d.getFullYear()).substr(2);     
            case 'yyyy':    return d.getFullYear();     
            case 'h':   return d.getHours() % 12 || 12;     
            case 'hh':  return zeroize(d.getHours() % 12 || 12);     
            case 'H':   return d.getHours();     
            case 'HH':  return zeroize(d.getHours());     
            case 'm':   return d.getMinutes();     
            case 'mm':  return zeroize(d.getMinutes());     
            case 's':   return d.getSeconds();     
            case 'ss':  return zeroize(d.getSeconds());     
            case 'l':   return zeroize(d.getMilliseconds(), 3);     
            case 'L':   var m = d.getMilliseconds();     
                    if (m > 99) m = Math.round(m / 10);     
                    return zeroize(m);     
            case 'tt':  return d.getHours() < 12 ? 'am' : 'pm';     
            case 'TT':  return d.getHours() < 12 ? 'AM' : 'PM';     
            case 'Z':   return d.toUTCString().match(/[A-Z]+$/);     
            // Return quoted strings with the surrounding quotes removed     
            default:    return $0.substr(1, $0.length - 2);     
        }     
    });     
}   

/**
 * js中获取上下文路径
 * @return {}
 */
function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
}

/**
 * 检查session是否过期
 * @param {} $response
 */
function checkTimeOut($response){
	var responseText=$response.responseText;
	if( responseText.indexOf('/j_spring_security_check')>0){
		var ss = getContextPath();
	  	location.href = ss + "/login.jsp";
	}
}

/**
 * 弹出成功提示信息
 */
function alertSuccess(){
	if(responseObj.msg == '' || responseObj.msg == undefined){
		responseObj.msg = '成功';
	}
	Ext.Msg.alert('提示', responseObj.msg);
}

/**
 * 弹出失败提示信息
 * @param {} responseObj
 */
function alertFailure(responseObj){
	if(responseObj.msg == '' || responseObj.msg == undefined){
		responseObj.msg = '失败';
	}
	Ext.Msg.alert('提示',responseObj.msg)
}

/**
 * 返回中英文混合字符串的长度。
 * @param {} str
 * @return {}
 */
function getStrlength(str){
	var len = str.match(/[^ -~]/g) == null ? str.length : str.length + str.match(/[^ -~]/g).length;
	return len;
}

/** 
* 截取指定长度的字符串（中英文混合）
* @author xwl 
* @param String str 要截取的字符串
* @param Int start 起始位置 
* @param Int len 截取长度
* @return String 截取以后字符串 
**/ 
function cutString(str,start,len){
  var reStr = "";
  var tempLen = 0;
  var cha = /^[\u2E80-\u9FFF]+$/;

  if(getStrlength(str) <= len){
    return str;
  }
  for(i=start; i< start+len; i++){ 
    if(cha.test(str.substr(i,1))){ 
      reStr += str.substr(i,1);
      tempLen = tempLen + 2;
    } else{
      reStr += str.substr(i,1);
      tempLen = tempLen + 1;
    }
    if(tempLen >= len){
    	if(reStr == str){
    		return reStr;
    	}else{
    		return reStr + '…';
    	}
     }
  }
}


function isChinese(str)
{
     var lst = /[u00-uFF]/;       
     return !lst.test(str);      
}





